<!--
 Copyright (c) 2017,2018,2019,2020,2021,2022 Klaus Landsdorf (http://node-red.plus/)
 All rights reserved.
 node-red-contrib-modbus - The BSD 3-Clause License

 @author <a href="mailto:klaus.landsdorf@bianco-royal.de">Klaus Landsdorf</a> (Bianco Royal)
-->
<script type="text/javascript">
  RED.nodes.registerType('modbus-flex-connector', {
    category: 'modbus',
    color: '#E9967A',
    defaults: {
      name: {value: ''},
      maxReconnectsPerMinute: {value: 4, required: true, validate: RED.validators.number()},
      emptyQueue: {value: false},
      showStatusActivities: {value: false},
      showErrors: {value: false},
      server: {type: 'modbus-client', required: true}
    },
    inputs: 1,
    outputs: 1,
    align: "left",
    icon: 'modbus.png',
    paletteLabel: 'Modbus-Flex-Connector',
    label: function () {
      return this.name || 'Modbus Flex Connector'
    }
  })
</script>


<script type="text/x-red" data-template-name="modbus-flex-connector">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-server"><i class="icon-globe"></i> <span data-i18n="modbus-contrib.label.server"></span></label>
        <input type="text" id="node-input-server">
    </div>
    <!-- <hr>
    <div class="form-row">
        <label for="node-input-maxReconnectsPerMinute"><i class="icon-tag"></i>
        <span data-i18n="modbus-contrib.label.maxReconnectsPerMinute"></span></label>
        <input type="text" id="node-input-maxReconnectsPerMinute" placeholder="4">
    </div>
    <div class="form-row">
        <label style="min-width:190px" for="node-input-emptyQueue"><i class="fa fa-th"></i> <span
        data-i18n="modbus-contrib.label.emptyQueue"></span></label>
        <input type="checkbox" id="node-input-emptyQueue" style="max-width:30px">
    </div> -->
    <hr>
    <div class="form-row">
        <label style="min-width:190px" for="node-input-showStatusActivities"><i class="fa fa-th"></i> <span
        data-i18n="modbus-contrib.label.showActivities"></span></label>
        <input type="checkbox" id="node-input-showStatusActivities" style="max-width:30px">
    </div>
    <div class="form-row">
        <label style="min-width:190px" for="node-input-showErrors"><i class="fa fa-th"></i> <span
        data-i18n="modbus-contrib.label.showErrors"></span></label>
        <input type="checkbox" id="node-input-showErrors" style="max-width:30px">
    </div>

</script>


<script type="text/x-red" data-help-name="modbus-flex-connector">
    <p>
        Modbus Flex Connector is a node for flexible input triggers to reconnect with new connection parameters.
    </p>

    <p>
        <pre>msg.payload.connectorType = 'TCP' || 'SERIAL'</pre>
    </p>

    <p>
        <h3>TCP options</h3>

        <ul>
            <li>msg.payload.tcpHost || node.tcpHost
            <li>msg.payload.tcpPort || node.tcpPort
            <li>msg.payload.tcpType || node.tcpType
            <li>msg.payload.unitId || node.unit_id
            <li>msg.payload.commandDelay || node.commandDelay
            <li>msg.payload.clientTimeout || node.clientTimeout
            <li>msg.payload.reconnectTimeout| || node.reconnectTimeout
        </ul>
    </p>

    <p>
        <h3>SERIAL options</h3>

        <ul>
          <li>msg.payload.serialPort || node.serialPort
          <li>msg.payload.serialBaudrate || node.serialBaudrate
          <li>msg.payload.serialDatabits || node.serialDatabits
          <li>msg.payload.serialStopbits || node.serialStopbits
          <li>msg.payload.serialParity || node.serialParity
          <li>msg.payload.serialType || node.serialType
          <li>msg.payload.serialConnectionDelay || node.serialConnectionDelay
          <li>msg.payload.unitId || node.unit_id
          <li>msg.payload.commandDelay || node.commandDelay
          <li>msg.payload.clientTimeout || node.clientTimeout
          <li>msg.payload.reconnectTimeout || node.reconnectTimeout
          <li>msg.payload.serialAsciiResponseStartDelimiter || node.serialAsciiResponseStartDelimiter
        </ul>
    </p>

    <p>
     <p>Function node code examples for TCP:</p>
     <code>
        msg.payload = {
        'connectorType': 'TCP',
        'tcpHost': '127.0.0.1',
        'unitId': 2 }
        return msg
     </code>

     <code>
        msg.payload = {
        'connectorType': 'TCP',
        'tcpHost': '127.0.0.1',
        'tcpPort': '10502',
        'unitId': 2 }
        return msg
     </code>

     <p>Function node code example for SERIAL:</p>
     <code>
        msg.payload = {
        'connectorType': 'SERIAL',
        'serialPort': '/dev/USB02',
        'serialBaudrate': '9600'
        'unitId': 2 }
        return msg
     </code>

</script>
